<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /* 
      生成器函数提前结束的方式
      1.generater.return 提前结束函数
      2.generater.throw() 向函数抛出一个异常    
    */
    function* foo() { }
    let generator = foo()
    console.log(generator.next());
    console.log(generator.throw(new Error("异常信息"))); //如果没有捕获异常就会报错
  </script>

</body>

</html>